import React, { useEffect } from "react";
import { connect } from "react-redux";
import { compose } from "recompose";
import LeftMenu from "components/main/leftMenu";
import RightContent from "components/main/rightContent";
import { withRouter } from "react-router-dom";
import { message } from "antd";
import Loading from "../../components/base/loading";

import "assets/less/view/main/index.less";

const Main = props => {
  const { isLogin, isRender, history } = props;

  useEffect(() => {
    if (isRender && !isLogin) {
      history.push("/login");
      message.error("请先登录！", 1);
      return;
    }
    document.title = "白 - 可视化数据"
  }, [isLogin, isRender]);

  return (
    <div className="main">
      {isRender ? (
        isLogin ? (
          <>
            <div className="main-left">
              <LeftMenu />
            </div>
            <div className="main-right">
              <RightContent />
            </div>
          </>
        ) : null
      ) : <Loading />}
    </div>
  );
};

export default compose(
  connect(
    store => ({
      isLogin: store.home.isLogin,
      isRender: store.home.isRender
    })
  ),
  withRouter
)(Main);
